package fr.inserm.umr915.vcfserver.bio.ucsc.ensgene;


import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import com.sleepycat.bind.tuple.TupleBinding;



import fr.inserm.umr915.vcfserver.bio.Segment;
import fr.inserm.umr915.vcfserver.bio.berkeley.DatabaseManager;
import fr.inserm.umr915.vcfserver.xml.XmlStreamSerializer;


public class EnsGeneHandler extends DatabaseManager<EnsGene>
	{
	private EnsGene.Binding dataBinding=new EnsGene.Binding();
	private EnsGene.StaxSerializer satx=new EnsGene.StaxSerializer();
	private EnsGene.Parser parser=new EnsGene.Parser();
	
	@Override
	public TupleBinding< EnsGene> getDataBinding()
		{
		return this.dataBinding;
		}
	
	@Override
	public XmlStreamSerializer<EnsGene> getXmlStreamSerializer()
		{
		return satx;
		}
	
	@Override
	public EnsGene parse(String line) throws IOException
		{
		EnsGene g= parser.parse(getDelim().split(line));
		if(!acceptChromosome(g.getChrom())) return null;
		return g;
		}
	@Override
	protected Set<String> getNames(EnsGene g)
		{
		Set<String> set=new HashSet<String>();
		set.add(g.getName());
		return set;
		}
	@Override
	public Segment getSegment(EnsGene o) {
		return new Segment(
			o.getChrom(),
			o.getTxStart(),
			o.getTxEnd()
			);
		}
	}
